<?php

namespace App\Rules;

use App\Models\DepositSetup;
use Illuminate\Contracts\Validation\Rule;

class TradeQueueStoreAmount implements Rule
{
    /**
     * Create a new rule instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Determine if the validation rule passes.
     *
     * @param  string  $attribute
     * @param  mixed  $value
     * @return bool
     */
    public function passes($attribute, $value)
    {
        $amount = DepositSetup::first();
        if(!$amount) {
            return ['error_code'=>'F005004','message'=>'入金暂未设置！'];
        }
        // 数据库的值
        $deposit_setup = DepositSetup::orderBy('id','desc')->first();

        switch (request('type')) {
            case 'deposit':
                if($deposit_setup->max_amount < $value || $value < $deposit_setup->min_amount) {
                    return false;
                }
                return true;
            case 'withdraw':
                if($value<1) {
                    return false;
                }
                return true;
            default:
                return false;
        }

    }

    /**
     * Get the validation error message.
     *
     * @return string
     */
    public function message()
    {
        return ['error_code'=>'F005005','message'=>'金额不在制定区间内！'];

    }
}
